package com.example.tomatotodo;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.tomatotodo.model.TodoConstants;

public class TodoCardFragment extends Fragment {

    private static final String ARG_NAME = "name";
    private static final String ARG_CATEGORY = "category";

    public static TodoCardFragment newInstance(String name, String category) {
        TodoCardFragment fragment = new TodoCardFragment();
        Bundle args = new Bundle();
        args.putString(ARG_NAME, name);
        args.putString(ARG_CATEGORY, category);
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_todo_card, container, false);

        TextView tvName = view.findViewById(R.id.tv_task_name);
        TextView tvCategory = view.findViewById(R.id.tv_task_category);

        if (getArguments() != null) {
            tvName.setText(getArguments().getString(ARG_NAME));

            // 根据类型显示相应的中文描述
            String category = getArguments().getString(ARG_CATEGORY);
            if (TodoConstants.TYPE_POMODORO.equals(category)) {
                tvCategory.setText("普通番茄钟");
            } else if (TodoConstants.TYPE_GOAL.equals(category)) {
                tvCategory.setText("定目标");
            } else {
                tvCategory.setText(category); // 如果不是预定义类型，则直接显示原值
            }
        }

        return view;
    }
}
